package com.receive.gate.message;
import org.apache.commons.collections4.map.HashedMap;

import com.base.listen.BaseServiceSession;
import com.base.listen.ServerListen;
import com.google.gson.Gson;
import com.hibernate.modle.impl.TbUserInfo;
import com.hibernate.modle.impl.TbUserModle;
import com.modle.manage.ModleManage;
import com.msg.ClientMsg;
import com.msg.Message;

public class ReceivedGateMessage {
	public static void Read(BaseServiceSession baseSession) {
		Gson gson = new Gson();
		String msgString = baseSession.getMsgString().toString();
		Message user= gson.fromJson(msgString, Message.class);
		if(user.getJsonString().length() != 0) {
			TbUserModle tbUserModle = ModleManage.getInstance().getTbUserManage().readModle(user.getSessionId());
			TbUserInfo tbUser = tbUserModle.getUserInfo();
			tbUser.setAgre(6);
			tbUser.setNameString("bbb");
			tbUser.setLoginTime(System.currentTimeMillis());
			tbUser.setRewardMap(new HashedMap<Integer,Integer>(1,1));
			tbUserModle.setTb_data(gson.toJson(tbUser));
			ModleManage.getInstance().getTbUserManage().writeModle(user.getSessionId(),tbUserModle);	
			
			ClientMsg res = new ClientMsg();
			res.setCode(1);
			res.setSessionId(user.getSessionId());
			String jsonStr = gson.toJson(res, ClientMsg.class);
			ServerListen.sendMessage(baseSession.getCtx(), jsonStr);
		}		
	}
}
